package com.china.school.interceptor;

import com.china.school.pojo.User;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Method;
import java.rmi.RemoteException;

public class AfterThrowingTest implements ThrowsAdvice {


    /**
     如果抛出的是 RemoteException异常那么将调用该方法
     * @param ex
     * @throws Throwable
     */
    public void afterThrowing(RemoteException ex) throws Throwable {
        // Do something with remote exception
        System.out.println("-----afterThrowing--1个参数-");

    }
    /**
     * @param method    可选：切入的方法
     * @param args      可选：切入的方法的参数
     * @param target    可选：目标对象
     * @param throwable 必填 : 异常子类，出现这个异常类的子类，则会进入这个通知。
     */
    public void afterThrowing(Method method, Object[] args, Object target, Throwable throwable) {
        System.out.println("-----afterThrowing--4个参数-");
    }

    public static void main(String[] args) throws Exception {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("XmlAopTest.xml");
        User user = ctx.getBean(User.class);
        user.eatError();
    }
}
